package cn.com.web.Servlet;

import cn.com.domain.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/AlterBeforeStudentServlet")
public class AlterBeforeStudentServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取要修改的学生参数并封装为对象
        String sidstr = request.getParameter("sid");
        String stuname = request.getParameter("stuname");
        String sex = request.getParameter("sex");
        String academy = request.getParameter("academy");
        int sid=0;
        if (sidstr!=null)
            sid=Integer.parseInt(sidstr);
        Student beforestu=new Student(sid,stuname,sex,academy);

        //将要修改的学生存到session域里
        HttpSession session = request.getSession();
        session.setAttribute("beforestu",beforestu);

        //重定向到alterStudent.jsp，填写修改后的学生信息
        response.sendRedirect(request.getContextPath()+"/alterStudent.jsp");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
